//
//  OrderXQViewController.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/8/11.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "OrderXQViewController.h"
#import "ListTableViewCell.h"
#import "FaHuoViewController.h"
#import "XiangQingViewController.h"
#import "IGOrderDetailApi.h"
#import "OrderDetailModel.h"
#import "IntroViewController.h"
#import "IGAddOrderApi.h"
#import "BuyCllowerViewController.h"
#import "IGTakeOrderApi.h"
#import "TLChatViewController.h"
#import "RefundApplyVC.h"
#import "RejectRefundVC.h"
#import "RefundInfoTableViewCell.h"
#import "SellerRefundTableViewCell.h"
#import "IGRefundProofCell.h"
#import "IGCancleOrderApi.h"
#import "IGAgreeRefundApi.h"
#import "IGOrderRefundModel.h"
#import "MyOrderViewController.h"
#import "IGGoodsAddOrderApi.h"
#import "QueRenViewController.h"
#import "GoodsDetailVC.h"
#import "SDPhotoBrowser.h"
#import "IGUpPhotoVC.h"
#import "IGCancleTrueOrderApi.h"

#define  SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define AUTOLAYOUTSIZE(size) ((size) * (SCREENWIDTH / 375))

@interface OrderXQViewController () <UITableViewDelegate, UITableViewDataSource,UIAlertViewDelegate>
{
    UIButton *bottomBtn;
    UIButton *bottomBtn2;
     UIButton *bottomBtn3;
    NSString *old;
    NSInteger type;
    NSString *timeStr;
    UIAlertView *alertView;
    UIAlertView *alertView1;
    
    NSInteger secondsCountDown;//倒计时总时长
    NSTimer *countDownTimer;
}

@property (weak, nonatomic) IBOutlet UITableView *table;
@property(nonatomic,strong)IGOrderDetailApi *detailApi;
@property(nonatomic,strong)IGTakeOrderApi *takeOrderApi;
@property(nonatomic,strong)IGCancleOrderApi *cancleOrderApi;
@property(nonatomic,strong)IGCancleTrueOrderApi *cancleTrueOrderApi;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) OrderDetailModel *orderIistInfo;
@property (nonatomic, strong) IGOrderRefundModel *refundInfo;
@property(nonatomic,strong)UILabel *timeLab;
@property(nonatomic,strong)IGAgreeRefundApi *agreeRefundApi;

@end

@implementation OrderXQViewController

#pragma mark -懒加载
-(NSMutableArray *)dataArray
{
    if (!_dataArray)
    {
        _dataArray=[NSMutableArray array];
    }
    return _dataArray;
}
#pragma mark -生命周期
- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.title = @"订单详情";
    self.title = NSLocalizedString(@"Order Details", nil);
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    self.table.backgroundColor = [UIColor c2Color];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.table.width, 1)];
    view.backgroundColor = self.table.backgroundColor;
    self.table.tableHeaderView = view;
     [self.table registerClass:[RefundInfoTableViewCell class] forCellReuseIdentifier:@"RefundInfoTableViewCell"];
     [self.table registerClass:[SellerRefundTableViewCell class] forCellReuseIdentifier:@"SellerRefundTableViewCell"];
     [self.table registerClass:[IGRefundProofCell class] forCellReuseIdentifier:@"IGRefundProofCell"];
    self.detailApi = [IGOrderDetailApi new];
    [self requestData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestData1) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self requestData];
}

#pragma mark- 该页面进入前台并处于活动状态时调用
-(void)requestData1
{
    _detailApi.oid=self.oid;
    [self.detailApi startWithDecodeClass:[IGOrderDetailResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGOrderDetailResp *resp=responseObject;
            IGOrderDetailModel *model=resp.data;
            BOOL isCheak = NO;
            if (![_orderIistInfo.status isEqualToString:model.order.status])
            {
                isCheak = YES;
            }
            _orderIistInfo = model.order;
            _refundInfo=model.orderRefund;
            [self.table reloadData];
            if (isCheak)
            {
                [self cheak];
            }
            [self.table reloadData];
        }
    }];
}

-(void)requestData
{
    self.detailApi = [IGOrderDetailApi new];
    _detailApi.oid=self.oid;
    self.orderIistInfo = [OrderDetailModel new];
    [self.detailApi startWithDecodeClass:[IGOrderDetailResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGOrderDetailResp *resp=responseObject;
            IGOrderDetailModel *model=resp.data;
            _orderIistInfo = model.order;
            _refundInfo=model.orderRefund;
            [self.table reloadData];
            [self cheak];
            [self.table reloadData];
        }
    }];
}
- (void)cheak
{
    self.table.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.table.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    if (!bottomBtn)
    {
        bottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        bottomBtn.backgroundColor = [UIColor appColor];
        [bottomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        bottomBtn.hidden = YES;
//        [bottomBtn setTitle:@"去付款" forState:UIControlStateNormal];
        [bottomBtn setTitle:NSLocalizedString(@"Go to the payment",nil) forState:UIControlStateNormal];
        [bottomBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [bottomBtn addTarget:self action:@selector(bottomBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        bottomBtn.titleLabel.font = [UIFont font16];
        [self.view addSubview:bottomBtn];
        [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make)
         {
            make.right.bottom.mas_equalTo(0);
            make.width.mas_equalTo(KSCREENWIDTH/2);
            make.height.mas_equalTo(AUTOLAYOUTSIZE(50));
        }];
    }
   
    if (!bottomBtn2) {
        bottomBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        bottomBtn2.backgroundColor = [UIColor c3Color];
        [bottomBtn2 setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
        bottomBtn2.hidden=YES;
//        [bottomBtn2 setTitle:@"取消订单" forState:UIControlStateNormal];
        [bottomBtn2 setTitle:NSLocalizedString(@"Cancel the Order", nil) forState:UIControlStateNormal];
        [bottomBtn2 addTarget:self action:@selector(bottomBtn2Action:) forControlEvents:UIControlEventTouchUpInside];
        bottomBtn2.titleLabel.font = [UIFont font16];
        [self.view addSubview:bottomBtn2];
        [bottomBtn2 mas_makeConstraints:^(MASConstraintMaker *make)
         {
            make.left.bottom.mas_equalTo(0);
            make.width.mas_equalTo(KSCREENWIDTH/2);
            make.height.mas_equalTo(AUTOLAYOUTSIZE(50));
        }];
    }
    if (!bottomBtn3) {
        bottomBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        bottomBtn3.backgroundColor = [UIColor appColor];
        [bottomBtn3 setTitleColor:[UIColor c3Color] forState:UIControlStateNormal];
        bottomBtn3.hidden=YES;
//        [bottomBtn3 setTitle:@"申请退款" forState:UIControlStateNormal];
        [bottomBtn3 setTitle:NSLocalizedString(@"Apply for Refund", nil) forState:UIControlStateNormal];
        [bottomBtn3 addTarget:self action:@selector(bottomBtn3Click:) forControlEvents:UIControlEventTouchUpInside];
        bottomBtn3.titleLabel.font = [UIFont font16];
        [self.view addSubview:bottomBtn3];
        
        [bottomBtn3 mas_makeConstraints:^(MASConstraintMaker *make)
         {
             make.left.right.bottom.mas_equalTo(0);
             make.height.mas_equalTo(AUTOLAYOUTSIZE(50));
         }];
    }
    if([_orderIistInfo.status integerValue]==0||[_orderIistInfo.status integerValue]==2 ||[_orderIistInfo.status integerValue]==7){
            NSDate *currenDate = [NSDate dateWithTimeIntervalSinceNow:0];
            NSTimeInterval timeInterval = [currenDate timeIntervalSince1970];
            NSString *timeString = [NSString stringWithFormat:@"%.0f", timeInterval];
             __block NSInteger time=0;
           if ([_orderIistInfo.status integerValue]==0)
           {
               time = 1800- (timeString.integerValue - _orderIistInfo.createTime.integerValue);
          }
           if([_orderIistInfo.status integerValue]==2)
            {
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *date = [dateFormatter dateFromString:_orderIistInfo.sendTime];
                NSTimeInterval timeInterval = [date timeIntervalSince1970];
                NSString *sendTime = [NSString stringWithFormat:@"%.0f", timeInterval];
                time = 15*24*60*60-((timeString.integerValue - sendTime.integerValue));
            }
              if  ([_orderIistInfo.status integerValue]==7)
            {
                NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
                [dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *date1 = [dateFormatter1 dateFromString: _refundInfo.requestTime];
                NSTimeInterval timeInterval1 = [date1 timeIntervalSince1970];
                NSString *requestTime = [NSString stringWithFormat:@"%.0f", timeInterval1];
                 time = 3*24*60*60 - (timeString.integerValue -requestTime.integerValue);
            }
            NSString *str_day=[NSString stringWithFormat:@"%02ld",time/(24*3600)];
            NSString *str_hour = [NSString stringWithFormat:@"%02ld",(time%(24*3600))/3600];//时
            NSString *str_minute = [NSString stringWithFormat:@"%02ld",(time%3600)/60];//分
            NSString *str_second = [NSString stringWithFormat:@"%02ld",time%60];//秒
            if ([_orderIistInfo.status integerValue]==0) {
                timeStr = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
                }
           if ([_orderIistInfo.status integerValue]==2||[_orderIistInfo.status integerValue]==7) {
                timeStr = [NSString stringWithFormat:@"%@天%@小时%@分",str_day,str_hour,str_minute];
             }
            // 创建一个派发队列 优先级是默认
            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
            dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0); // 每秒执行
            dispatch_source_set_event_handler(_timer, ^{
                if (time <= 0) { // 倒计时结束 关闭
                    dispatch_source_cancel(_timer);
                    dispatch_async(dispatch_get_main_queue(), ^{
                        bottomBtn.hidden = YES;
                        bottomBtn2.hidden=YES;
                        if ([_orderIistInfo.status integerValue]==0) {
                            if ([self isChinese]) {
                                _timeLab.text=@"剩余00:00自动取消";
                            } else _timeLab.text=@"00:00 auto cancel";
                            time=0;
                            timeStr = @"00:00";
                        }
                        if ([_orderIistInfo.status integerValue]==2||[_orderIistInfo.status integerValue]==7) {
                            if ([self isChinese]) {
                                _timeLab.text=@"剩余00:00:00自动确认";
                                timeStr = @"00:00:00";
                            } else {
                                _timeLab.text=@"Auto Confirm with 00:00:00 Left";
                                timeStr = @"00:00:00";
                            }
   
                            time=0;
                        }
                    });
                } else {
                    dispatch_async(dispatch_get_main_queue(), ^{
                       NSString *str_hour = [NSString stringWithFormat:@"%02ld",(time%(24*3600))/3600];//时
                       NSString *str_minute = [NSString stringWithFormat:@"%02ld",(time%3600)/60];//分
                       NSString *str_second = [NSString stringWithFormat:@"%02ld",time%60];//秒
                        if ([_orderIistInfo.status integerValue]==0) {
                            timeStr = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
                            if ([self isChinese]) {
                                _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动取消",timeStr];
                            } else _timeLab.text=[NSString stringWithFormat:@"%@ auto cancel",timeStr];
                        }
                        if ([_orderIistInfo.status integerValue]==2||[_orderIistInfo.status integerValue]==7) {
                            if ([self isChinese]) {
                                timeStr = [NSString stringWithFormat:@"%@:%@:%@",str_day,str_hour,str_minute];
                                _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动确认",timeStr];
                            } else {
                                timeStr = [NSString stringWithFormat:@"%@:%@:%@",str_day,str_hour,str_minute];
                                _timeLab.text=[NSString stringWithFormat:@"Auto Confirm with %@ Left",timeStr];
                            }

                        }
                          time--;
//                        if (time==0) {
//                            [self requestData];
//                        }
                    });
                }
            });
            dispatch_resume(_timer);
//            bottomBtn.hidden = NO;
//            bottomBtn2.hidden=NO;
    }
}

#pragma mark — UITableViewDelegate, UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([_orderIistInfo.type integerValue]==1) {
        return 7;
    }else{
        if (_refundInfo.refundProofs.count==0) {
              if (_refundInfo.refundTime==nil) {
                  if (_refundInfo.proof.count==0) {
                      if (_refundInfo.requestTime==nil) {
                          return 7;
                      }
                      return 8;
                  }
                return 9;
            }
              return 10;
        }
    }
    return 11;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        if ([_orderIistInfo.type integerValue]==1) {
            return 0;
        }
        return 1;
    }
    if (section == 2)
    {
        if ([_orderIistInfo.type integerValue]==1) {
            return 0;
        }
        return 1;
    }
    if (section == 7||section==8||section==9||section==10)
    {
        if ([_orderIistInfo.type integerValue]==1) {
            return 0;
        }
        return 1;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cel = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cel.selectionStyle = UITableViewCellSelectionStyleNone;
    cel.backgroundColor=[UIColor c3Color];
    CGFloat h = [self tableView:tableView heightForRowAtIndexPath:indexPath];
#pragma mark------------交易状态section0
    if (indexPath.section==0) {//交易状态
        UIView *stateView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.width, h)];
        stateView.backgroundColor=[UIColor appColor];
        [cel addSubview:stateView];
        //图片
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(15, 20, 50, 50)];
        imageView.centerY=stateView.centerY;
        imageView.image=[UIImage imageNamed:@"等待付款"];
        [stateView addSubview:imageView];
        //状态
        UILabel *stateLab=[[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10, 15, 150, 0)];
//        stateLab.text=@"等待付款                      ";
        stateLab.text = NSLocalizedString(@"To be Paid", nil);
        [stateLab sizeToFit];
        stateLab.font=[UIFont font16];
        stateLab.textColor=[UIColor c3Color];
        [stateView addSubview:stateLab];
        
        self.timeLab=[[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10, 0, 0, 0)];
        _timeLab.bottom=h-30;
        
        
        if ([self isChinese]) {
            _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动关闭",timeStr];
        } else {
            _timeLab.text=[NSString stringWithFormat:@"Auto Close with %@ Left",timeStr];
        }
        
        
        [_timeLab sizeToFit];
        _timeLab.font=[UIFont font12];
        _timeLab.textColor=[UIColor c3Color];
        [stateView addSubview:_timeLab];
        //status;  //订单状态(0未支付;1已支付但未发货;2已发货;3已完成;4退款中;5已退款;6已取消;7退款确认中)
        if (_isMyBuy)
        {//我购买的
            if ([_orderIistInfo.status integerValue]==0||[_orderIistInfo.status integerValue]==1||[_orderIistInfo.status integerValue]==2) {
                self.table.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
                self.table.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 44, 0);
               }
            if ([_orderIistInfo.status integerValue]==0) {
                imageView.image=[UIImage imageNamed:@"等待付款"];
//                stateLab.text=@"等待付款";
                stateLab.text = NSLocalizedString(@"To be Paid", nil);
                [stateLab sizeToFit];
                if ([self isChinese]) {
                    _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动取消",timeStr];
                } else {
                    _timeLab.text=[NSString stringWithFormat:@"%@ auto cancel",timeStr];
                }
                if ([timeStr isEqualToString:@"00:00"] || [timeStr isEqualToString:@"00:00:00"])
                {
                    bottomBtn.hidden=YES;
                    bottomBtn2.hidden=YES;
                } else {
                    bottomBtn.hidden=NO;
                    bottomBtn2.hidden=NO;
                }
                bottomBtn3.hidden=YES;
//                [bottomBtn setTitle:@"去付款" forState: UIControlStateNormal];
                 [bottomBtn setTitle:NSLocalizedString(@"Go to the payment", nil) forState: UIControlStateNormal];
//                [bottomBtn2 setTitle:@"取消订单" forState:UIControlStateNormal];
                 [bottomBtn2 setTitle:NSLocalizedString(@"Cancel the Order", nil) forState:UIControlStateNormal];
            }
            if ([_orderIistInfo.status integerValue]==1) {
                imageView.image=[UIImage imageNamed:@"等待卖家发货"];
                stateLab.centerY=h/2;
//                stateLab.text=@"等待卖家发货";
                stateLab.text = NSLocalizedString(@"Wait for Delivery", nil);
                  [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                if ([_orderIistInfo.allowRefund integerValue]==2) {
                    bottomBtn3.hidden=YES;
                }else{
                bottomBtn3.hidden=NO;
//                [bottomBtn3 setTitle:@"申请退款" forState: UIControlStateNormal];
                [bottomBtn3 setTitle:NSLocalizedString(@"Apply for Refund", nil) forState: UIControlStateNormal];
                [bottomBtn3 addTarget:self action:@selector(bottomBtn3Click:) forControlEvents:UIControlEventTouchUpInside];
                }
            }
            if ([_orderIistInfo.status integerValue]==2) {
                imageView.image=[UIImage imageNamed:@"卖家已发货"];
//                stateLab.text=@"待确认收货";
                stateLab.text = NSLocalizedString(@"Delivery to be confirmed", nil);
                  [stateLab sizeToFit];
                if ([self isChinese]) {
                    _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动确认",timeStr];
                } else {
                    _timeLab.text=[NSString stringWithFormat:@"Auto Confirm with %@ Left",timeStr];
                }
                if ([timeStr isEqualToString:@"00:00"] || [timeStr isEqualToString:@"00:00:00"])
                {
                    if ([_orderIistInfo.allowRefund integerValue]==2) {
                        bottomBtn.hidden=YES;
                        bottomBtn2.hidden=YES;
                         bottomBtn3.hidden=YES;
                    }else{
                    bottomBtn.hidden=YES;
                    bottomBtn2.hidden=YES;
                    }
                } else {
                    if ([_orderIistInfo.allowRefund integerValue]==2) {
                        bottomBtn.hidden=YES;
                        bottomBtn2.hidden=YES;
                        bottomBtn3.hidden=NO;
//                        [bottomBtn3 setTitle:@"确认收货" forState: UIControlStateNormal];
                        [bottomBtn3 setTitle:NSLocalizedString(@"Confirm Delivery",nil) forState: UIControlStateNormal];
                        [bottomBtn3 addTarget:self action:@selector(bottomBtn3Click:) forControlEvents:UIControlEventTouchUpInside];
                    }else{
                    bottomBtn.hidden=NO;
                    bottomBtn2.hidden=NO;
                    bottomBtn3.hidden=YES;
//                    [bottomBtn setTitle:@"确认收货" forState: UIControlStateNormal];
//                    [bottomBtn2 setTitle:@"申请退款" forState:UIControlStateNormal];
                    [bottomBtn setTitle:NSLocalizedString(@"Confirm Delivery",nil) forState: UIControlStateNormal];
                    [bottomBtn2 setTitle:NSLocalizedString(@"Apply for Refund", nil) forState:UIControlStateNormal];
                   }
               }
            }
            if ([_orderIistInfo.status integerValue]==3) {
                imageView.image=[UIImage imageNamed:@"交易成功"];
                stateLab.centerY=h/2;
//                stateLab.text=@"交易成功";
                stateLab.text=NSLocalizedString(@"Transaction Successful", nil);
                  [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==4) {
                imageView.image=[UIImage imageNamed:@"退款中"];
                stateLab.centerY=h/2;
//                stateLab.text=@"退款中";
                stateLab.text = NSLocalizedString(@"Refunding",nil);
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==5) {
                imageView.image=[UIImage imageNamed:@"已退款"];
                stateLab.centerY=h/2;
//                stateLab.text=@"已退款";
                stateLab.text=NSLocalizedString(@"Refunded", nil);
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==7) {
                imageView.image=[UIImage imageNamed:@"退款确认中"];
                if ([self isChinese]) {
                    _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动确认",timeStr];
                } else _timeLab.text=[NSString stringWithFormat:@"Auto Confirm with %@ Left",timeStr];
//                stateLab.text=@"退款确认中";
                stateLab.text=NSLocalizedString(@"Refund Confirming", nil);
                  [stateLab sizeToFit];
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==6) {
                self.table.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
                self.table.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 44, 0);
                imageView.image=[UIImage imageNamed:@"订单已取消"];
                stateLab.centerY=h/2;
//                stateLab.text=@"订单已取消";
                stateLab.text = NSLocalizedString(@"Order Canceled",nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
        }
        if(!_isMyBuy)
        {//我出售的
            if ([_orderIistInfo.status integerValue]==1||[_orderIistInfo.status integerValue]==7) {
                self.table.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
                self.table.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 44, 0);
            }
            if ([_orderIistInfo.status integerValue]==0) {
                imageView.image=[UIImage imageNamed:@"等待付款"];
//                stateLab.text=@"等待买家付款";
                stateLab.text = NSLocalizedString(@"To be Paid", nil);
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==1) {
                imageView.image=[UIImage imageNamed:@"等待卖家发货"];
                stateLab.centerY=h/2;
//                stateLab.text=@"待发货";
                stateLab.text = NSLocalizedString(@"Wait for Delivery", nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=NO;
//                [bottomBtn3 setTitle:@"发货" forState: UIControlStateNormal];
                [bottomBtn3 setTitle:NSLocalizedString(@"Shipped", nil) forState: UIControlStateNormal];
            }
            if ([_orderIistInfo.status integerValue]==2) {
                imageView.image=[UIImage imageNamed:@"卖家已发货"];
//                stateLab.text=@"等待买家收货";
                stateLab.text = NSLocalizedString(@"Delivery to be confirmed", nil);
                [stateLab sizeToFit];
                if ([self isChinese]) {
                    _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动确认",timeStr];
                } else _timeLab.text=[NSString stringWithFormat:@"Auto Confirm with %@ Left",timeStr];
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==3) {
                imageView.image=[UIImage imageNamed:@"交易成功"];
                stateLab.centerY=h/2;
//                stateLab.text=@"交易成功";
                stateLab.text=NSLocalizedString(@"Transaction Successful", nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==4) {
                imageView.image=[UIImage imageNamed:@"退款中"];
                stateLab.centerY=h/2;
//                stateLab.text=@"退款中";
                stateLab.text = NSLocalizedString(@"Refunding", nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==5) {
                imageView.image=[UIImage imageNamed:@"已退款"];
                stateLab.centerY=h/2;
//                stateLab.text=@"已退款";
                stateLab.text = NSLocalizedString(@"Refunded", nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
            if ([_orderIistInfo.status integerValue]==7) {
                imageView.image=[UIImage imageNamed:@"退款确认中"];
//                stateLab.text=@"买家申请退款";
                stateLab.text=NSLocalizedString(@"Buyer Applying for Refund", nil);
                [stateLab sizeToFit];
                if ([self isChinese]) {
                    _timeLab.text=[NSString stringWithFormat:@"剩余 %@ 自动确认",timeStr];
                } else _timeLab.text=[NSString stringWithFormat:@"Auto Confirm with %@ Left",timeStr];
                if ([timeStr isEqualToString:@"00:00"] || [timeStr isEqualToString:@"00:00:00"])
                {
                    bottomBtn.hidden=YES;
                    bottomBtn2.hidden=YES;
                } else {
                    bottomBtn.hidden=NO;
                    bottomBtn2.hidden=NO;
                }
                bottomBtn3.hidden=YES;
//                [bottomBtn2 setTitle:@"拒绝退款" forState: UIControlStateNormal];
//                [bottomBtn setTitle:@"同意退款" forState:UIControlStateNormal];
                [bottomBtn2 setTitle:NSLocalizedString(@"Refuse Refund", nil) forState: UIControlStateNormal];
                [bottomBtn setTitle:NSLocalizedString(@"Refund Approved", nil) forState:UIControlStateNormal];
            }
            if ([_orderIistInfo.status integerValue]==6) {
                imageView.image=[UIImage imageNamed:@"订单已取消"];
                stateLab.centerY=h/2;
                stateLab.text=NSLocalizedString(@"Order Canceled", nil);
                [stateLab sizeToFit];
                _timeLab.hidden=YES;
                bottomBtn.hidden=YES;
                bottomBtn2.hidden=YES;
                bottomBtn3.hidden=YES;
            }
        }
        return cel;
#pragma mark------------配送方式section1
    }else if (indexPath.section==1) {//配送方式
        if ([_orderIistInfo.type integerValue]==1) {
            cel.hidden=YES;
        }
        if (_orderIistInfo.shipping==nil) {
            cel.hidden=YES;
        }
        UIImageView *deliverImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        deliverImageView.image=[UIImage imageNamed:@"椭圆3"];
        [cel addSubview:deliverImageView];
        
        UILabel *state = [[UILabel alloc] initWithFrame:CGRectZero];
        state.font = [UIFont font14];
//        state.text = [NSString stringWithFormat:@"配送方式：%@", _orderIistInfo.shipping.length>0?_orderIistInfo.shipping:@""];
        state.text = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"Shipping Method",nil),_orderIistInfo.shipping.length>0?_orderIistInfo.shipping:NSLocalizedString(@"Nothing",nil)];
        [state sizeToFit];
        [cel.contentView addSubview:state];
        
        UILabel *mun = [[UILabel alloc] initWithFrame:CGRectZero];
        mun.font = [UIFont font14];
//        mun.text = [NSString stringWithFormat:@"运单编号：%@", _orderIistInfo.expressOrder.length>0?_orderIistInfo.expressOrder:@""];
        mun.text = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"Freight Note No.",nil),_orderIistInfo.expressOrder.length>0?_orderIistInfo.expressOrder:NSLocalizedString(@"Nothing",nil)];
        [mun sizeToFit];
        [cel.contentView addSubview:mun];
        deliverImageView.x=10;
        deliverImageView.centerY=h/2;
        state.x = deliverImageView.right+5;
        state.y = (h-state.height-mun.height-10)/2;
        
        mun.x = state.x;
        mun.y = state.bottom + 5;
#pragma mark------------收货地址section2
    } else if (indexPath.section==2) {//收货地址
        if ([_orderIistInfo.type integerValue]==1) {
            cel.hidden=YES;
        }
        if (_orderIistInfo.address==nil) {
            cel.hidden=YES;
        }
        cel.userInteractionEnabled=YES;
        UIImageView *takeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        takeImageView.image=[UIImage imageNamed:@"椭圆2拷贝"];
         [cel addSubview:takeImageView];
        
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectZero];
        name.font = [UIFont font14];
//        name.text = [NSString stringWithFormat:@"收货人：%@", _orderIistInfo.consignee.length>0?_orderIistInfo.consignee:@"张三"];
        name.text = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"Recipient",nil),_orderIistInfo.consignee.length>0?_orderIistInfo.consignee:NSLocalizedString(@"Nothing",nil)];
        [name sizeToFit];
        [cel.contentView addSubview:name];
        
        UILabel *tel = [[UILabel alloc] initWithFrame:CGRectZero];
        tel.font = [UIFont font14];
        tel.text = [NSString stringWithFormat:@"%@", _orderIistInfo.phone.length>0?_orderIistInfo.phone:@""];
        [tel sizeToFit];
        [cel.contentView addSubview:tel];
        
        UILabel *adderss = [[UILabel alloc] initWithFrame:CGRectZero];
        adderss.font = [UIFont font14];
        [adderss setContentMode:UIViewContentModeTop];
        [adderss setLineBreakMode:NSLineBreakByWordWrapping];
        [adderss setNumberOfLines:0];
//        NSString *str=[NSString stringWithFormat:@"收货地址:%@", _orderIistInfo.address.length>0?_orderIistInfo.address:@"北京亦庄开发区"];
        NSString *str = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"Recipient Address",nil),_orderIistInfo.address.length>0?_orderIistInfo.address:NSLocalizedString(@"Nothing",nil)];
        adderss.text=str;
        [adderss sizeToFit];
        adderss.width=KSCREENWIDTH-20-takeImageView.width-5;
        adderss.height=34;
        adderss.text = [str stringByAppendingString:@"\n "];
        [cel.contentView addSubview:adderss];
        
        takeImageView.x=10;
        takeImageView.centerY=h/2;
        name.x = takeImageView.right+5;
        name.y=16;
        adderss.x = name.x;
        adderss.y = name.bottom + 5;
        tel.right = KSCREENWIDTH - 15;
        tel.top = name.top;
#pragma mark------------作品信息section3
    } else if (indexPath.section==3){//购买作品信息
        ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oredrCell"];
        if (cell==nil)
        {
            cell = [[ListTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"oredrCell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.backColor=@"1";
        cell.data = _orderIistInfo;
        [cell setNeedsLayout];
        return cell;
#pragma mark------------付款信息section4
    }else if (indexPath.section==4){//实付款
        if(self.isMyBuy==NO){
            cel.hidden=YES;
        }
//        UILabel *yidian = [[UILabel alloc] initWithFrame:CGRectZero];
//        yidian.font = [UIFont font14];
//        yidian.text =@"艺点";
//        [yidian sizeToFit];
//        yidian.hidden=YES;
//        [cel addSubview:yidian];
//
//        UILabel *yidianNum = [[UILabel alloc] initWithFrame:CGRectZero];
//        yidianNum.font = [UIFont font14];
//        yidianNum.text =[NSString stringWithFormat:@"%@",_orderIistInfo.artPoints.length>0?_orderIistInfo.artPoints:@"0.00"];
//        [yidianNum sizeToFit];
//        yidianNum.hidden=YES;
//        [cel addSubview:yidianNum];
//        yidian.x=15;
//        yidian.y=15;
//        yidianNum.right=tableView.right-15;
//        yidianNum.y=yidian.y;
        
        UILabel *payment = [[UILabel alloc] initWithFrame:CGRectZero];
        payment.font = [UIFont font14];
//        payment.text =@"实付款";
        payment.text=NSLocalizedString(@"Actual Payment", nil);
        [payment sizeToFit];
        [cel addSubview:payment];
        
        UILabel *money = [[UILabel alloc] initWithFrame:CGRectZero];
        money.font = [UIFont font14];
        money.text = [NSString stringWithFormat:@" ¥%@", _orderIistInfo.actuallyPay];
        [money sizeToFit];
        [cel addSubview:money];
        payment.x=15;
        payment.y=10;
        money.right=tableView.right-15;
        money.y=payment.y;
#pragma mark------------备注section5
    }else if (indexPath.section==5){//备注
        cel.selectionStyle = UITableViewCellSelectionStyleDefault;
        NSString *str1=_orderIistInfo.orderContent;
        NSDictionary *attribute = @{NSFontAttributeName: [UIFont font14]};
        CGSize labelSize = [str1 boundingRectWithSize:CGSizeMake(5000, 200) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
 
        UILabel *remark = [[UILabel alloc] initWithFrame:CGRectZero];
        remark.font = [UIFont font14];
        remark.text =NSLocalizedString(@"Note Information:", nil);
        [remark sizeToFit];
        remark.x=15;
        remark.centerY=cel.centerY;
        [cel addSubview: remark];
        UILabel *remarkDetail = [[UILabel alloc] initWithFrame:CGRectMake(remark.right+5, 0, KSCREENWIDTH-remark.width-15, h)];
        remarkDetail.font = [UIFont font14];
        remarkDetail.textColor=[UIColor c5Color];
        remarkDetail.textAlignment=NSTextAlignmentLeft;
        remarkDetail.centerY=cel.centerY;
        if (labelSize.width>remarkDetail.width) {
            remarkDetail.text=NSLocalizedString(@"Click for Concrete Information", nil);
        }else{
            cel.userInteractionEnabled=NO;
//            remarkDetail.text = str1.length>0?str1:@"无";
             remarkDetail.text = str1.length>0?str1:NSLocalizedString(@"Nothing", nil);
        }
        [cel addSubview:remarkDetail];
    }
#pragma mark------------订单号section6
    else if (indexPath.section==6){//订单号
        UILabel *mun = [[UILabel alloc] initWithFrame:CGRectZero];
        mun.font = [UIFont systemFontOfSize:15];
//        mun.text = [NSString stringWithFormat:@"订单号：%@", _orderIistInfo.purOrder.length>0?_orderIistInfo.purOrder:@" "];
        mun.text = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"Order Number",nil),_orderIistInfo.purOrder.length>0?_orderIistInfo.purOrder:@" "];
        [mun sizeToFit];
        [cel.contentView addSubview:mun];
        
        UILabel *state = [[UILabel alloc] initWithFrame:CGRectZero];
        state.font = [UIFont systemFontOfSize:15];
        state.textColor = [UIColor appColor];
        [state sizeToFit];
        [cel.contentView addSubview:state];
        
        UILabel *time = [[UILabel alloc] initWithFrame:CGRectZero];
        time.font = [UIFont systemFontOfSize:13];
        time.textColor = [UIColor grayColor];
//        time.text = [@"下单时间：" stringByAppendingString:[NSDate timestampToString:_orderIistInfo.createTime Format:@"yyyy-MM-dd HH:mm:ss"]];
        NSString *orderTime = [NSString stringWithFormat:@"%@: ",NSLocalizedString(@"Order Time", nil)];
        time.text = [orderTime stringByAppendingString:[NSDate timestampToString:_orderIistInfo.createTime Format:@"yyyy-MM-dd HH:mm:ss"]];
        [time sizeToFit];
        [cel.contentView addSubview:time];
        
        mun.x = 15;
        mun.y = (h-mun.height-time.height-10)/2;
        
        time.x = mun.x;
        time.y = mun.bottom + 10;
        
        state.right = KSCREENWIDTH - 15;
        state.top = mun.top;
#pragma mark------------退款信息section7
    }else if (indexPath.section==7){//退款信息
        if (_refundInfo.requestTime==nil) {
            cel.hidden=YES;
        }
        RefundInfoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"RefundInfoTableViewCell" forIndexPath:indexPath];
       cell.refundInfomation=_refundInfo;
        return cell;
    }
#pragma mark------------申请退款凭证section8
    else if (indexPath.section==8){//退款凭证
        if (_refundInfo.proof.count==0) {
            cel.hidden=YES;
        }
        IGRefundProofCell *cell=[tableView dequeueReusableCellWithIdentifier:@"IGRefundProofCell" forIndexPath:indexPath];
        cell.proofImg=_refundInfo.proof;
        cell.tagBlock = ^(NSString *tag) {
            IGUpPhotoVC *vc=[[IGUpPhotoVC alloc]init];
            vc.photoArr=_refundInfo.proof;
            vc.imageTag=[tag integerValue];
            // 展示效果
            [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
            [self presentViewController:vc animated:YES completion:nil];
        };
        return cell;
   }
#pragma mark------------是否同意退款section9
   else if (indexPath.section==9){//卖家是否同意退款信息
       if (_refundInfo.refundReason==nil||[_orderIistInfo.status integerValue]==7) {
           cel.hidden=YES;
       }
       SellerRefundTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SellerRefundTableViewCell" forIndexPath:indexPath];
        cell.sellerRefundInfo=_refundInfo;
        return cell;
   }
#pragma mark------------拒绝退款凭证section10
    else if (indexPath.section==10){//拒绝退款凭证
        if (_refundInfo.refundProofs.count==0) {
            cel.hidden=YES;
        }
        IGRefundProofCell *cell=[tableView dequeueReusableCellWithIdentifier:@"IGRefundProofCell" forIndexPath:indexPath];
        cell.proofImg=_refundInfo.refundProofs;
        cell.tagBlock = ^(NSString *tag) {
            IGUpPhotoVC *vc=[[IGUpPhotoVC alloc]init];
            vc.photoArr=_refundInfo.refundProofs;
            vc.imageTag=[tag integerValue];
            [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
            [self presentViewController:vc animated:YES completion:nil];
        };
        return cell;
    }
    return cel;
}
#pragma mark =======viewForHeaderInSection
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==3)
    {
        CGFloat h = [self tableView:tableView heightForHeaderInSection:section];
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, h)];
        view.backgroundColor = [UIColor whiteColor];
        
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, 20, 20)];
        img.centerY = h/2;
        if (self.isMyBuy==YES)
        {
            img.image = [UIImage imageNamed:@"my_sale"];
        }
        else
        {
            img.image = [UIImage imageNamed:@"my_sell-8"];
        }
        img.contentMode = UIViewContentModeScaleAspectFill;
        [view addSubview:img];
        
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectZero];
        name.userInteractionEnabled = YES;
        name.text = _isMyBuy ? _orderIistInfo.sellerNike.length>0?_orderIistInfo.sellerNike:@"" : _orderIistInfo.buyerNike.length>0?_orderIistInfo.buyerNike:@"";
        name.font = [UIFont font14];
        [name sizeToFit];
        [view addSubview:name];
        name.x = img.right+8;
        name.centerY = h/2;
        
        UIImageView *chat = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        chat.right=tableView.right-15;

        chat.image=[UIImage imageNamed:@"me-mail"];
        [chat sizeToFit];
        chat.centerY = h/2;
        name.width=KSCREENWIDTH-15-img.width-8-chat.width-15-5;
        chat.userInteractionEnabled=YES;
        [view addSubview:chat];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toIntro)];
        [name addGestureRecognizer:tap];
        UITapGestureRecognizer *eTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toTalk)];
        [chat addGestureRecognizer:eTap];
        return view;
    }
    if (section==7) {
        CGFloat h1 = [self tableView:tableView heightForHeaderInSection:section];
        UIView *view1=[[UIView alloc]initWithFrame:CGRectZero];
        view1.backgroundColor=[UIColor c2Color];
        view1.left=tableView.left+15;
        view1.size=CGSizeMake(KSCREENWIDTH-15, h1);
        UILabel *refundInfo=[[UILabel alloc]initWithFrame:CGRectZero];
        refundInfo.backgroundColor=[UIColor c2Color];
//        refundInfo.text=@"退款信息";
        refundInfo.text=NSLocalizedString(@"Refund Information", nil);
        [refundInfo sizeToFit];
        refundInfo.y=(view1.height-refundInfo.height)/2;
        refundInfo.x=view1.x;
        refundInfo.font=[UIFont font14];
        refundInfo.textColor=[UIColor grayColor];
        refundInfo.textAlignment=NSTextAlignmentLeft;
        [view1 addSubview:refundInfo];
        return view1;
    }
    return nil;
}

#pragma mark =======viewForFooterInSection
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section==3)
    {        
        CGFloat h = [self tableView:tableView heightForFooterInSection:section];
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, h)];
        view.backgroundColor =[UIColor c2Color];
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, h-1)];
        v.backgroundColor = [UIColor whiteColor];
        [view addSubview:v];
        
        UILabel *msg = [[UILabel alloc] initWithFrame:CGRectZero];
        msg.font = [UIFont font14];
        [view addSubview:msg];
        
//        msg.text = _isMyBuy ? ([_orderIistInfo.artPoint floatValue] > 0 ? [NSString stringWithFormat:@"艺点已抵扣: ¥%@ 应付: ¥%@", _orderIistInfo.artPoint, _orderIistInfo.actuallyPay] : [NSString stringWithFormat:@"合计: ¥%@", _orderIistInfo.total.length>0?_orderIistInfo.total:@"0"]) :[NSString stringWithFormat:@"合计: ¥%@", _orderIistInfo.total.length>0?_orderIistInfo.total:@"0"];
        msg.text = _isMyBuy ? ([_orderIistInfo.artPoint floatValue] > 0 ? [NSString stringWithFormat:@"%@: ¥%@ %@: ¥%@", NSLocalizedString(@"Art Point Deducted",nil),_orderIistInfo.artPoint,NSLocalizedString(@"Payment",nil), _orderIistInfo.actuallyPay] : [NSString stringWithFormat:@"%@: ¥%@", NSLocalizedString(@"Total",nil),_orderIistInfo.total.length>0?_orderIistInfo.total:@"0"]) :[NSString stringWithFormat:@"%@: ¥%@", NSLocalizedString(@"Total",nil),_orderIistInfo.total.length>0?_orderIistInfo.total:@"0"];
        [msg sizeToFit];

        msg.right = view.width-15;
        msg.centerY=(view.height-1)/2;
        return view;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 3)
    {
        if ([_orderIistInfo.type integerValue]==1) {
            XiangQingViewController * vc= [[XiangQingViewController alloc]init];
            vc.p_id= _orderIistInfo.pId;
            vc.isRoot = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            GoodsDetailVC *vc=[[GoodsDetailVC alloc]init];
            vc.goodsId=_orderIistInfo.pId;
            [self.navigationController pushViewController:vc animated:YES];
        }

    }
    if (indexPath.section==2) {
        alertView1 = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Recipient Address",nil) message: _orderIistInfo.address delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alertView1 show];
    }
    if (indexPath.section==5) {
        alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Note Information:", nil) message:_orderIistInfo.orderContent delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alertView show];
    }
    if (indexPath.section==8) {
//            SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
//            photoBrowser.delegate = self;
//            photoBrowser.currentImageIndex = 0;
//            photoBrowser.imageCount = _refundInfo.proof.count;
//            photoBrowser.sourceImagesContainerView = self.table;
//            [photoBrowser show];
//        IGUpPhotoVC *vc=[[IGUpPhotoVC alloc]init];
//        vc.photoArr=_refundInfo.proof;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section==3)
    {
        return 40;
    }
    if (section==4) {
        return 1;
    }
    if (section==7) {
        return 25;
    }
    return .01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==0)
    {
        return 0.01f;
    }
    if (section==2) {
        if ([_orderIistInfo.type integerValue]!=1) {
            return 10.f;
        }
        return 0.01f;
    }
    if (section==3)
    {
        return 41.f;
    }
    if (section==4) {
        return 10.f;
    }
    if (section==7||section==9) {
        return 0.01f;
    }
    if (section==5) {
        return 10.f;
    }
    return 1.f;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 70;
    }
    if (indexPath.section==1) {
        if (_orderIistInfo.shipping==nil) {
            return 0.01;
        }
    }
    if (indexPath.section==2) {
        if (_orderIistInfo.address==nil) {
            return 0.01;
        }
    }
    if (indexPath.section==3)
    {
        return 80;
    }
    if (indexPath.section==4)
    {
        if(self.isMyBuy==NO){
            return 0.01f;
        }
        return 40;
        
    }
    if (indexPath.section==5) {
        return 40;
    }
    if (indexPath.section==7) {
        return 113;
    }
    if (indexPath.section==8) {
        if (_refundInfo.proof.count==0) {
            return 0.01f;
        }
            return GSCALE(125);
    }
    if (indexPath.section==9) {
        if (_refundInfo.refundTime==nil) {
            return 0.01f;
        }
        return 75;
    }
    if (indexPath.section==10) {
        if (_refundInfo.refundProofs.count==0) {
            return 0.01f;
        }
         return GSCALE(125);
    }
    return 75;
}
-(void)changeButton1Status{
    bottomBtn.enabled =YES;
}
#pragma mark === Button付款,确认收货,同意退款
- (void)bottomBtnAction:(UIButton *)btn
{
    if (self.isMyBuy==YES) {
        if ([_orderIistInfo.status integerValue]==0) {//去付款
            if ([_orderIistInfo.type integerValue]==1){
            IGAddOrderApi *api = [IGAddOrderApi new];
            api.worksId = _orderIistInfo.pId;
            api.orderId = _orderIistInfo.oId;
            [api startWithDecodeClass:[IGAddOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject)
                {
                    IGAddOrderResp *resp = responseObject;
                    IGAddOrderModel *model = resp.data;
                    BuyCllowerViewController *vc = [[BuyCllowerViewController alloc] init];
                    vc.type = 2;
                    vc.model = model;
                    [UIViewController ig_pushViewController:vc animated:YES];
                }
            }];
            }
        if ([_orderIistInfo.type integerValue]!=1) {//真品购买去付款
            IGGoodsAddOrderApi *orderApi = [IGGoodsAddOrderApi new];
            orderApi.goodsId = _orderIistInfo.pId;
            orderApi.orderId=_orderIistInfo.oId;
            [orderApi startWithDecodeClass:[IGGoodsAddOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject)
                {
                    IGGoodsAddOrderResp * resp = responseObject;
                    IGGoodsAddOrderModel *model = resp.data;
                    if ([model.method isEqualToString:@"toOrder"])
                    {
                        QueRenViewController * vc = [[QueRenViewController alloc] init];
                        vc.model = model;
                        vc.type = 2;
                        [UIViewController ig_pushViewController:vc animated:YES];
                    }
                }
            }];
        }
    }
        if ([_orderIistInfo.status integerValue]==2) {//确认收货
            bottomBtn.enabled=NO;
            [self performSelector:@selector(changeButton1Status) withObject:nil afterDelay:1.0f];//防止重复点击
            IGTakeOrderApi *takeOrApi = [IGTakeOrderApi new];
                        takeOrApi.oid=_orderIistInfo.oId;
                        takeOrApi.type=@"3";
                        [takeOrApi startWithDecodeClass:[IGTakeOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                            if (responseObject)
                            {
                                btn.hidden=YES;
//                                 [self presentMessageTips:@"发送成功!"];
                                [self presentMessageTips:NSLocalizedString(@"Sent Successfully", nil)];
                                [self.navigationController popViewControllerAnimated:YES];
                            }else{
//                                [self presentMessageTips:@"发送失败!"];
                                [self presentMessageTips:NSLocalizedString(@"Sending Failed", nil)];
                            }
                        }];
                    }
     }
    if(self.isMyBuy==NO){
          if ([_orderIistInfo.status integerValue]==7) {
              NSString *title = [[NSString alloc]init];
              if ([self isChinese]) {
                  title = [NSString stringWithFormat:@"确定同意%@元的退款",_orderIistInfo.total];
              } else title=[NSString stringWithFormat:@"Refund of RMB %@ Confirmed",_orderIistInfo.total];
              UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:title message:NSLocalizedString(@"After refund is approved, the payment will return to buyer's account directly.", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
              [alertview show];
          }
    }
   
}
#pragma mark------UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) { //OK
        [alertView dismissWithClickedButtonIndex:0 animated:YES];
        NSLog(@"点击了取消按钮");
    }
    if(buttonIndex==1){//同意退款
        self.agreeRefundApi=[[IGAgreeRefundApi alloc]init];
        _agreeRefundApi.oid=_orderIistInfo.oId;
        __weak typeof(self) weakSelf = self;
        [self.agreeRefundApi startWithDecodeClass:[IGAgreeRefundResp class]CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
            if (responseObject) {
                [weakSelf presentMessageTips:NSLocalizedString(@"Application Successful !", nil)];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            } else {
                [weakSelf presentMessageTips:NSLocalizedString(@"Application Failed !", nil)];
            }
        }];
    }
    
}
#pragma mark=====Button2 取消订单 申请退款 拒绝退款
-(void)bottomBtn2Action:(UIButton *)btn
{
    if (_isMyBuy) {
        if ([_orderIistInfo.status integerValue]==0) {//取消订单
            if ([_orderIistInfo.type integerValue]==1) {
                self.cancleOrderApi=[IGCancleOrderApi new];
                _cancleOrderApi.oid=_orderIistInfo.oId;
                _cancleOrderApi.uid=_orderIistInfo.buyerId;
                [self.cancleOrderApi startWithDecodeClass:[IGCancleOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                    if (responseObject)
                    {
                        [self requestData];
                    }
                }];
            }else{
                self.cancleTrueOrderApi=[IGCancleTrueOrderApi new];
                _cancleTrueOrderApi.oid=_orderIistInfo.oId;
                _cancleTrueOrderApi.uid=_orderIistInfo.buyerId;
                [self.cancleTrueOrderApi startWithDecodeClass:[IGCancleTrueOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                    if (responseObject)
                    {
                        [self requestData];
                    }
                }];
            }           
        }
        if ([_orderIistInfo.status integerValue]==2) {//申请退款
            [self refundViewController];
        }
    }
    if (self.isMyBuy==NO) {
        if ([_orderIistInfo.status integerValue]==7) {//拒绝退款
            [self rejectRefundViewController];
        }
    }
}
-(void)changeButton3Status{
    bottomBtn3.enabled =YES;
}
#pragma mark----Button3发货 申请退款
-(void)bottomBtn3Click:(UIButton *)btn{//申请退款,发货
    if (self.isMyBuy==YES) {
        if ([_orderIistInfo.status integerValue]==3) {//拒绝退款
            [self rejectRefundViewController];
        }
        if ([_orderIistInfo.status integerValue]==1) {//申请退款
            [self refundViewController];
        }
        if ([_orderIistInfo.type integerValue]!=1&&[_orderIistInfo.status integerValue]==2&&[_orderIistInfo.allowRefund integerValue]==2) {
            bottomBtn3.enabled=NO;
            [self performSelector:@selector(changeButton3Status) withObject:nil afterDelay:1.0f];//防止重复点击
            IGTakeOrderApi *takeOrApi = [IGTakeOrderApi new];
            takeOrApi.oid=_orderIistInfo.oId;
            takeOrApi.type=@"3";
            [takeOrApi startWithDecodeClass:[IGTakeOrderResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject)
                {
                    btn.hidden=YES;
//                    [self presentMessageTips:@"发送成功!"];
                    [self presentMessageTips:NSLocalizedString(@"Sent Successfully", nil)];
                    [self.navigationController popViewControllerAnimated:YES];
                }else{
//                    [self presentMessageTips:@"发送失败!"];

                    [self presentMessageTips:NSLocalizedString(@"Sending Failed", nil)];
                }
            }];
        }
    }
    if (self.isMyBuy==NO)
    {
        if ([_orderIistInfo.status integerValue]==1){  //发货
            FaHuoViewController * vc = [[FaHuoViewController alloc]initWithNibName:@"FaHuoViewController" bundle:nil];
            vc.o_id =_orderIistInfo.oId;
            [UIViewController ig_pushViewController:vc animated:YES];
        }
    }
}
#pragma mark ======= 跳转至用户列表页
- (void)toIntro
{
    if (_orderIistInfo.sellerId || _orderIistInfo.buyerId)
    {
        IntroViewController *vc = [[IntroViewController alloc] init];
        vc.u_id = _isMyBuy ? _orderIistInfo.sellerId : _orderIistInfo.buyerId;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
}
#pragma mark -跳转至私信界面
-(void)toTalk
{
    if (_orderIistInfo.sellerId||_orderIistInfo.buyerId) {
        if (_isMyBuy) {
            if ([_orderIistInfo.sellerId isEqualToString:[IGUser getUid]]) {
                [self presentMessageTips:NSLocalizedString(@"Don't send private message to yourself.", nil)];
                return;
            }
            TLChatViewController *vc = [TLChatViewController new];
            vc.otherId = _orderIistInfo.sellerId;
            vc.navigationItem.title = _orderIistInfo.sellerNike;
            [UIViewController ig_pushViewController:vc animated:YES];
        }
        if (!_isMyBuy) {
            if ([_orderIistInfo.buyerId isEqualToString:[IGUser getUid]]) {
                [self presentMessageTips:NSLocalizedString(@"Don't send private message to yourself.", nil)];
                return;
            }
            TLChatViewController *vc = [TLChatViewController new];
            vc.otherId = _orderIistInfo.buyerId;
            vc.navigationItem.title = _orderIistInfo.buyerNike;
            [UIViewController ig_pushViewController:vc animated:YES];
        }
    }
}
#pragma mark -跳转到申请退款界面
-(void)refundViewController
{
        RefundApplyVC * vc1 = [[RefundApplyVC alloc]init];
        vc1.orderInfo=_orderIistInfo;
        [UIViewController ig_pushViewController:vc1 animated:YES];
}
#pragma mark -跳转到拒绝退款界面
-(void)rejectRefundViewController
{
    RejectRefundVC *rejectVc=[[RejectRefundVC alloc]init];
    rejectVc.oid=_orderIistInfo.oId;
    [UIViewController ig_pushViewController:rejectVc animated:YES];
}

#pragma mark - 语言判断

-(BOOL)isChinese{
    NSString *clanguage = [[NSUserDefaults standardUserDefaults] objectForKey:KLanguage];
    if ([clanguage containsString:@"zh-Hans"]) {
        return YES;
    } else return NO;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
